<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form form class="form-horizontal" id="form" method="post" action="">
                            <input type="hidden" name="id" value="{$coach['id']}" />
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 姓名 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="name" id="name" class="rcol-xs-10 col-sm-5"
                                           value="{:$coach['name']}">
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle"></span>
                                            </span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 年龄 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="age" id="age" class="rcol-xs-10 col-sm-5"
                                           value="{:$coach['age']}">
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle"></span>
                                            </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 性别 </label>
                                <div class="col-sm-9">
                                   <select id="sex" name="sex" >
                                        <option value="0" <if condition="$coach['sex'] eq 0">selected="selected"</if>>男</option>
                                        <option value="1" <if condition="$coach['sex'] eq 1">selected="selected"</if>>女</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 手机号 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="phone" id="phone" class="rcol-xs-10 col-sm-5"
                                           value="{$coach['phone']}">
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle"></span>
                                            </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 驾龄 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="driver_age" id="driver_age" class="rcol-xs-10 col-sm-5"
                                           value="{$coach['driver_age']}">
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle"></span>
                                            </span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 照片 </label>
                                <div class="col-sm-9">
                                    <div class="col-xs-10 col-sm-5">{:UpImage('img',100,100,$coach['img'])}</div>
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle">仅支持jpg、gif、png、bmp、jpeg，且小于1MB。</span>
                                            </span>
                                </div>

                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                 <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 驾照类型 </label>
                                <div class="col-sm-9">
                                    <select id="driver_type" name="driver_type" >
                                        <option value="0" >--请选择驾照类型--</option>
                                        <volist name="license_type" id="val">
                                            <option value="{$val['id']}" <if condition="$coach['driver_type'] eq $val['id']">selected="selected"</if>>{$val['type']}</option>
                                        </volist>
                                       <!--  <option value="0" selected="selected">--请选择驾照类型--</option>
                                        <option value="1">c1</option> -->
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 分配车辆 </label>
                                <div class="col-sm-9" id="car_list">
                                        <!-- <volist name="car" id="val">
                                            <if condition="$coach['car_id'] eq $val['id']">
                                            
                                            <input type="radio" name="car_id" checked="checked" class ="car_id" value="{$val['id']}" >{$val['car_num']}--<volist name="license_type" id="l"><if condition="$l['id'] eq $val['l_type']">{$l['type']}</if></volist>
                                            </if>
                                            <if condition="$val['status'] eq 0">
                                            
                                            <input type="radio" name="car_id" class ="car_id" value="{$val['id']}" >{$val['car_num']}--<volist name="license_type" id="l"><if condition="$l['id'] eq $val['l_type']">{$l['type']}</if></volist>
                                            </if>
                                        </volist> -->
                                       
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 教练简介 </label>
                                <div class="col-sm-9">
                                    <textarea name="intro" id="intro"
                                                  style="width:100%;height:400px;">{$coach['intro']}</textarea>
                                    <span class="help-inline col-xs-12 col-sm-7">
                                                <span class="middle"></span>
                                            </span>
                                </div>
                            </div>
                            
                            <div class="space-4"></div>

                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info" id="submit" type="submit">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </form>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer"/>

</div><!-- /.main-container -->

<include file="Public/footerjs"/>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    // $(function () {
    //     $(".check-all").click(function () {
    //         $(".ids").prop("checked", this.checked);
    //     });
    //     $(".ids").click(function () {
    //         var option = $(".ids");
    //         option.each(function (i) {
    //             if (!this.checked) {
    //                 $(".check-all").prop("checked", false);
    //                 return false;
    //             } else {
    //                 $(".check-all").prop("checked", true);
    //             }
    //         });
    //     });
    // })
//表单验证
// function check(){
//   var name = $('.name').val();
//   var age = $('.age').val();
//   var sex = $('.sex').val();
//   var driver_age = $('.driver_age').val();
//   var id_card = $('.id_card').val();
//   var phone = $('.phone').val();
//   var l_type = $('.l_type').val();
//   if(name){
//      alert('')
//   }
//   return false;
// }

$(function () {
        // $("#tabs").tabs();
        // var editor = KindEditor.create('textarea[name="content"]', {
        //     uploadJson: '__PUBLIC__/kindeditor/php/upload_json.php',
        //     fileManagerJson: '__PUBLIC__/kindeditor/php/file_manager_json.php',
        //     allowFileManager: true,
        //     afterBlur: function () {
        //         this.sync();
        //     }
        // });
        $("#submit").click(function () {
              var name = $.trim($("#name").val());
              var age = $.trim($("#age").val());
              var sex = $.trim($("#sex").val());
              var phone = $.trim($("#phone").val());
              var driver_age = $.trim($("#driver_age").val());
              var driver_type = $.trim($("#driver_type").val());
              var car_id =$(".car_id");
              var regAge = /^\d{1}|\d{2}$/;
              var regPhone = /^1[356789]\d{9}$/;
            if (name == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "请填写教练姓名！",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (age == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "请填写年龄!",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (!regAge.test(age)) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "年龄为数字！",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (phone == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "请填写手机号码!",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (!regPhone.test(phone)) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "手机号码格式不正确！",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (driver_age == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "请填写教练驾龄!",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (!regAge.test(driver_age)) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "教练驾龄为数字！",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (driver_type == 0) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "请选择驾照类型!",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (car_id == null) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "请分配车辆!",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            // console.log('111');
            // $("#form").submit();
        });

        
    });
$(function(){
    var l_type = $('#driver_type').val();
    var c_id = {:$coach['car_id']};
    var driver_type = {:$coach['driver_type']};
    $.ajax({
            url: '{:U('Car/getCar')}',
            type: 'post',
            dataType: 'json',
            data: {'l_type': l_type},
            success : function (data){
                // var data = eval('('+data+')');//转换为对象
                    var str = '';
                    if(driver_type == l_type){
                        str += '<input type="radio" name="car_id" checked="checked" class ="car_id" value="{:$coach['car_id']}" >'+'---'+'{$coach['car_num']}';

                    }
                if(data.res ==1){
                    $('#car_list').empty();
                    var car_data = data.data;
                    for (var i = 0; i < car_data.length; i++) {
                            str += '<input type="radio" name="car_id"  class ="car_id" value="'+car_data[i]['id']+'" >'+'---'+car_data[i]['car_num'];    
                    }
                    $('#car_list').html(str);
                }else{
                    $('#car_list').empty();
                    $('#car_list').html(str);
                }
            } 
        })
});
$('#driver_type').change(
    function(event) {
        var l_type = $('#driver_type').val();
        var c_id = {:$coach['car_id']};
        var driver_type = {:$coach['driver_type']};
        $.ajax({
            url: '{:U('Car/getCar')}',
            type: 'post',
            dataType: 'json',
            data: {'l_type': l_type},
            success : function (data){
                // var data = eval('('+data+')');//转换为对象
                    var str = '';
                    if(driver_type == l_type ){
                        str += '<input type="radio" name="car_id" checked="checked" class ="car_id" value="{:$coach['car_id']}" >'+'---'+'{$coach['car_num']}';
                    }
                if(data.res ==1){
                    $('#car_list').empty();
                    var car_data = data.data;
                    for (var i = 0; i < car_data.length; i++) {
                            str += '<input type="radio" name="car_id"  class ="car_id" value="'+car_data[i]['id']+'" >'+'---'+car_data[i]['car_num'];                        
                    }
                    // alert(str)
                    $('#car_list').html(str);
                }else{
                    $('#car_list').empty();
                    $('#car_list').html(str);
                    if(driver_type != l_type){

                       bootbox.dialog({
                            title: '友情提示：',
                            message: "该驾照类型下没有更多的车辆信息,请先添加车辆信息!",
                            buttons: {
                                "success": {
                                    "label": "确定",
                                    "className": "btn-danger"
                                }
                            }
                            });
                        return false; 
                    }
                }
            } 
        })
        
});
</script>
</body>
</html>
